﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using GKS.TBMS.Portal.Models;

namespace GKS.TBMS.Portal.Controllers
{
    public class SecurityController : Controller
    {
        private PortalEntities db = new PortalEntities();

        // GET: /Security/
        public ActionResult Index()
        {
            return View(db.UserRoleTeams.ToList());
        }

        // GET: /Security/Details/5
        public ActionResult Details(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            UserRoleTeam userroleteam = db.UserRoleTeams.Find(id);
            if (userroleteam == null)
            {
                return HttpNotFound();
            }
            return View(userroleteam);
        }

        // GET: /Security/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: /Security/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include="UserId,FirstName,MiddleName,LastName,Username,RoleId,RoleName,RoleDescription,TeamId,TeamName,TeamDescription")] UserRoleTeam userroleteam)
        {
            if (ModelState.IsValid)
            {
                userroleteam.UserId = Guid.NewGuid();
                db.UserRoleTeams.Add(userroleteam);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(userroleteam);
        }

        // GET: /Security/Edit/5
        public ActionResult Edit(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            UserRoleTeam userroleteam = db.UserRoleTeams.Find(id);
            if (userroleteam == null)
            {
                return HttpNotFound();
            }
            return View(userroleteam);
        }

        // POST: /Security/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include="UserId,FirstName,MiddleName,LastName,Username,RoleId,RoleName,RoleDescription,TeamId,TeamName,TeamDescription")] UserRoleTeam userroleteam)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userroleteam).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(userroleteam);
        }

        // GET: /Security/Delete/5
        public ActionResult Delete(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            UserRoleTeam userroleteam = db.UserRoleTeams.Find(id);
            if (userroleteam == null)
            {
                return HttpNotFound();
            }
            return View(userroleteam);
        }

        // POST: /Security/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(Guid id)
        {
            UserRoleTeam userroleteam = db.UserRoleTeams.Find(id);
            db.UserRoleTeams.Remove(userroleteam);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
